import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-23
 * Time: 19:44
 */
public class test_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i]=in.nextInt();
            }

            int[] dp = new int[n + 1];

            dp[1] = nums[0];

            for (int i = 2; i < n + 1; i++) {
                dp[i] = Math.min(dp[i - 2], dp[i - 1]) + nums[i - 1];
            }

            System.out.println(Math.min(dp[n-1], dp[n]));

        }
    }
}
